<?php
namespace app\operation\controller;
use app\common\controller\OperationBase;
/*自动下课记录*/
class AutoLessonend extends OperationBase{
	protected $beforeActionList = [
        'before_index'=>['only'=>'index'],
    ];
	function _initialize() {
		parent::_initialize();  
    }
	function index(){
		$this->assign("shops",db("Shop")->where("parent_id!=0")->order("id desc")->field("shop_name,id,parent_id")->select());
		echo $this->fetch();
	}	
	function ajax_index(){
		$this->ajax($this->_ajax_index());
	}
	function detail(){
		$model=db("AutoLessonEnd")->find(input('id'));
		$this->assign("model",$model);
		echo $this->fetch();
	}
	///////////////////////////////////////////////////////////////////////////////////
	/**
	 * 权限菜单
	 **/
	function before_index(){
		$auth_group=sp_get_auth_menu_3("20061005");
		$this->assign("menus",$auth_group);
	}
	
	private function _ajax_index(){
		$query=array(
		 'employee_name'=>array("field" =>"a.employee_name","operator" =>"="),
		 'member_name'=>array("field" =>"a.member_name","operator" =>"="),
		 'reservation_name'=>array("field" =>"a.reservation_name","operator" =>"="),
		 'result_status'=>array("field" =>"a.result_status","operator" =>"="),
		 'start_status'=>array("field" =>"a.start_status","operator" =>"="),
		 'sign_status'=>array("field" =>"a.sign_status","operator" =>"="),
		);
		$shop_id=input("shop_id");
		$draw=input("draw",0)+1;//请求时间		 
		$where_and=join(" and ",sp_get_param_sql(request()->isPost(),$query));
		if(!empty($shop_id)){
			$where_and.=" and a.shop_id=$shop_id ";
		}
		$total=db("AutoLessonEnd")->alias("a")->join([['m_shop b','a.shop_id=b.id','left']])->where($where_and)->count(1);
		$list=db("AutoLessonEnd")->alias("a")->field("a.*,b.shop_name")->join([['m_shop b','a.shop_id=b.id','left']])->where($where_and)->order($this->get_order())->limit($this->get_limit())->fetchsql(FALSE)->select();
		return array('pageData'=>$list,'total'=>$total,"draw"=>$draw);
	}
}
